package com.zhu.day.util;

import java.util.Comparator;
import java.util.Map;
import java.util.Optional;
import java.util.Set;

public class ValentinePlayUtil {

    /**
     * 是否完成了碎片
     *
     * @param curScore
     * @param targetScore
     * @return
     */
    public static boolean checkIf(long curScore, long targetScore) {
        if (curScore >= targetScore) {
            return true;
        }
        return false;
    }

    /**
     * @param configs
     * @param score
     * @param <T>
     * @return
     */
    public static <T> Optional<T> getConfigScore(Map<Long, T> configs, Long score) {

        Set<Long> keys = configs.keySet();
        Optional<Long> key = keys.stream().sorted(Comparator.reverseOrder()).filter(val -> score.compareTo(val) >= 0).findFirst();
        return key.flatMap(val -> Optional.ofNullable(configs.get(val)));
    }

    /**
     * @param configs
     * @param rank
     * @param <T>
     * @return
     */
    public static <T> Optional<T> getConfig(Map<Integer, T> configs, Integer rank) {

        Set<Integer> keys = configs.keySet();
        Optional<Integer> key = keys.stream().sorted().filter(val -> rank.compareTo(val) <= 0).findFirst();
        return key.flatMap(val -> Optional.ofNullable(configs.get(val)));
    }

    /**
     * 获取文案
     *
     * @param score
     * @return
     */

}
